import numpy as np
import pandas as pd
import scipy as sp

def logloss(act, pred):
    epsilon = 1e-15
    pred = sp.maximum(epsilon, pred)
    pred = sp.minimum(1-epsilon, pred)
    ll = sum(act*sp.log(pred) + sp.subtract(1,act)*sp.log(sp.subtract(1,pred)))
    ll = ll * -1.0/len(act)
    return ll

def accu(act,pred):
    n=0;
    for i in range(len(act)):
        if act[i]==1 and pred[i]>=0.5:
            n=n+1
        if act[i]==0 and pred[i]<0.5:
            n=n+1
    return n/len(act)
        

if __name__=='__main__':
    
    pre=pd.read_csv('data/pro/pro_lgbm_train.csv')
    train_all=pd.read_csv('data/cutData/feature_v6.csv')

    last_sum=pd.merge(pre,train_all,how='right',on='sort')

    #ll=logloss(last_sum['label'],last_sum['lgbm_prob'])

    #pre=pd.read_csv('data/pro/pro_xgb_train.csv')
    #train_all=pd.read_csv('data/cutData/feature_v6.csv')

    #last_sum=pd.merge(pre,train_all,how='right',on='sort')

    #ll=logloss(last_sum['label'],last_sum['xgb_prob'])

    ll=accu(last_sum['label'],last_sum['lgbm_prob'])
    
    print(ll)#0.0964/97.5%    0.0959/97%
    
